import javax.swing.*;
import java.io.*;
import java.net.URI;
import java.net.URL;
import java.util.Iterator;
import java.util.Scanner;

/**
 * Created by Scott Tiger.
 * User: tomaszsocha
 * Date: 2010-05-05
 * Time: 17:25:42
 */
public class ItemZk extends JComboBox{

    public ItemZk(String itemName) {
        String fileLocation = "bw/"+itemName+"Zk.csv";
        Scanner scanner = null;
        try {
            InputStream ms = getClass().getClassLoader().getResourceAsStream(fileLocation);
            scanner = new Scanner(ms,"UTF-8");
            while ( scanner.hasNextLine() ){
            String line = scanner.nextLine() ;
            String pref = line.substring(0, line.indexOf(","));
            String suf =line.substring(line.indexOf(",")+1);
            this.addItem(pref+" "+suf);

            }

            } catch ( Exception e) {
                System.out.println(System.getProperty("user.home"));
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.

                System.exit(0);
            }
            finally {
              //ensure the underlying stream is always closed
                assert scanner != null;
                scanner.close();
            }

}

    public ItemZk(File file) {
            Scanner scanner = null;
        try {
            scanner = new Scanner(file,"UTF-8");
            while ( scanner.hasNextLine() ){
            String line = scanner.nextLine() ;
            String pref = line.substring(0, line.indexOf(","));
            String suf =line.substring(line.indexOf(",")+1);
            this.addItem(pref+" "+suf);

            }

            } catch ( Exception e) {
                System.out.println(System.getProperty("user.home"));
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.

                System.exit(0);
            }
            finally {
              //ensure the underlying stream is always closed
                assert scanner != null;
                scanner.close();
            }
    }
}
